package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.MediaMapper;
import com.yuwubao.uav.tool.service.MediaService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class MediaServiceImpl implements MediaService {

    private static final Logger logger = LogManager.getLogger(MediaServiceImpl.class.getName());

    @Resource
    private MediaMapper mediaMapper;

    @Override
    public void deleteMedia(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    mediaMapper.deleteMedia(pageData);
                }
            }

        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateMedia(PageData pageData) throws Exception {
        try{
            mediaMapper.updateMedia(pageData);
        }catch (Exception e) {
            logger.debug("",e);
            e.printStackTrace();
        }
    }
    @Override
    public void disableOrEnableMedia(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    mediaMapper.disableOrEnableMedia(pageData);
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
            e.printStackTrace();
        }
    }
    @Override
    public void addMedia(PageData pageData) throws Exception {
        try{
            mediaMapper.addMedia(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listMedia(PageData pageData) throws Exception {
        try{
            return mediaMapper.listMedia(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listMediaCount(PageData pageData) throws Exception {
        try{
            return mediaMapper.listMediaCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }
}
